//
//  SLUserAccount.swift
//  Sina15
//
//  Created by 盼 on 16/4/10.
//  Copyright © 2016年 pan. All rights reserved.
//

import UIKit

class SLUserAccount: NSObject {
    
    var access_token: String?
    var uid: String?
    
    //一得到用户信息就计算过期日期
    var expires_in: NSTimeInterval = 0 {
        
        didSet {
            expire_date = NSDate(timeIntervalSinceNow: expires_in)
        }
    }
    
    //添加过期字段，开发者账号的过期日期是5年，测试帐号的过期日期是1天
    var expire_date: NSDate?
    var name: String?
    var avatar_large: String?
    
    
    //KVC构造函数实现字典转模型
    init(dict: [String: AnyObject]) {
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    //重写undefinedKey的方法
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }

    //MARK: 把对象转换成字符串，方便调试
    override var description: String {
        let keys = ["access_token","avatar_large","name","uid","expires_in","expires_date"]
        let dict = self.dictionaryWithValuesForKeys(keys)
        return dict.description
    }
    
}
